<?php
/**
 * (crontab) sp-获取请求报告（类型）
 */
namespace App\Crontab\Daily\SpApi;

use App\Jobs\AmazonApi\SpApi\GrabGetReports as GGrabGetReports;
use App\Models\Basics\AmazonAccount;
class GrabGetReports
{
    /**
     * 亚马逊报告-通用
     * @param $report_types
     * @param $created_since
     * @param $created_until
     * @param array $where
     * @return void
     */
    public static function grab($report_types,$created_since,$created_until, array $where = []){
        $where['api'] = 1;
        $accounts = AmazonAccount::optionsForApi($where);
        $re = [];
        foreach ($accounts as $account){
            $marketplace_ids = $account->account_country->pluck('marketplace_id')->toArray();
            if ($marketplace_ids) {
                foreach ($marketplace_ids as $key => $val){
                    $marketplace_id = [$val];
                    GGrabGetReports::dispatch($account,$report_types,$marketplace_id,$created_since,$created_until)->onQueue('sp-report');
                }
            }
            $re[$account->id] = true;
        }
        var_dump($re);
    }
}
